import numpy as np
import pandas as pd

# Set random seed for reproducibility
np.random.seed(42)

# Number of samples
n_samples = 1000

# Generate data for correct posture (label 1)
n_correct = int(n_samples * 0.6)  # 60% correct postures
correct_posture = np.random.uniform(
    low=[2.5, 2.5, 2.0, 2.0, 2.0, 2.0],
    high=[4.0, 4.0, 3.5, 3.5, 3.5, 3.5],
    size=(n_correct, 6)
)
correct_labels = np.ones(n_correct)

# Generate data for incorrect posture (label 0)
n_incorrect = n_samples - n_correct
# Different types of incorrect postures
incorrect_postures = []

# Leaning forward (high pressure on front sensors)
n_forward = n_incorrect // 3
forward = np.random.uniform(
    low=[4.0, 4.0, 0.5, 0.5, 0.5, 0.5],
    high=[6.0, 6.0, 2.0, 2.0, 2.0, 2.0],
    size=(n_forward, 6)
)
incorrect_postures.append(forward)

# Leaning backward (high pressure on back sensors)
n_backward = n_incorrect // 3
backward = np.random.uniform(
    low=[0.5, 0.5, 4.0, 4.0, 4.0, 4.0],
    high=[2.0, 2.0, 6.0, 6.0, 6.0, 6.0],
    size=(n_backward, 6)
)
incorrect_postures.append(backward)

# Leaning to one side
n_side = n_incorrect - n_forward - n_backward
side = np.random.uniform(
    low=[0.5, 4.0, 0.5, 4.0, 0.5, 4.0],
    high=[2.0, 6.0, 2.0, 6.0, 2.0, 6.0],
    size=(n_side, 6)
)
incorrect_postures.append(side)

incorrect_posture = np.vstack(incorrect_postures)
incorrect_labels = np.zeros(n_incorrect)

# Combine all data
X = np.vstack([correct_posture, incorrect_posture])
y = np.hstack([correct_labels, incorrect_labels])

# Create DataFrame
columns = [f'sensor{i+1}' for i in range(6)] + ['label']
df = pd.DataFrame(np.column_stack([X, y]), columns=columns)

# Add some random noise to make data more realistic
noise = np.random.normal(0, 0.1, df.shape)
df.iloc[:, :6] += noise[:, :6]

# Ensure values are within 0-6 range
df.iloc[:, :6] = df.iloc[:, :6].clip(0, 6)

# Shuffle the dataset
df = df.sample(frac=1, random_state=42).reset_index(drop=True)

# Save to CSV
df.to_csv('sitting_posture_dataset.csv', index=False) 